function prof_data = profdata(num_ep, x_col, y_col);

% PROFDATA - create array of profile data
%
%    DATA = PROFDATA(EP, X, Y) creates an array of profile data
%    for workspace arrays named EP1, EP2, etc.  EP is the number
%    of workspace arrays, X is the column number where the X data
%    is stored and Y is the column number where the Y data is stored.

% By:   S.C. Molitor (smolitor@med.unc.edu)
% Date: August 17, 2000

% default parameters

CAMERA_SCALE = 4.16;		% Cohu scaling - 4.16 pixels/um

% initialize output

prof_data = [];

% validate arguments

if (nargin ~= 3)
   msgbox('Invalid number of arguments', 'PROFDATA Error', 'warn');
   return
elseif (~isscalar(num_ep))
   msgbox('EP must be a scalar', 'PROFDATA Error', 'warn');
   return
elseif (~isscalar(x_col))
   msgbox('X must be a scalar', 'PROFDATA Error', 'warn');
   return
elseif (~isscalar(y_col))
   msgbox('Y must be a scalar', 'PROFDATA Error', 'warn');
   return
end

% make sure arrays exist
% make sure indices are appropriate for profiles
% scale distance from soma

for i = 1 : num_ep
   ep_array = evalin('base', sprintf('ep%d', i));
   if (size(ep_array, 2) >= max(x_col, y_col))
      prof_data(:, 1) = ep_array(2 : end, x_col)/CAMERA_SCALE;
      prof_data(:, end + 1) = ep_array(2 : end, y_col);
   else
      msgbox(sprintf('EP%d must exist & have %d columns', i, max(x_col, y_col)), 'PROFDATA Error', 'warn');
      return
   end
end

% truncate short profiles

max_ind = max(find(prof_data > 0));
if (~isempty(max_ind))
   [prof_row, prof_col] = ind2sub(size(prof_data), max_ind);
   prof_data = prof_data(1 : prof_row, 1 : prof_col);
end
return
